//
//  visitorViewController.swift
//  微博
//
//  Created by 王朝阳 on 16/4/7.
//  Copyright © 2016年 王朝阳. All rights reserved.
//

import UIKit

class visitorViewController: UITableViewController {
    
    /// 记录用户登陆的状态
    private var login: Bool = false
    /// 访客视图
    var vsview: visitorView?
   
    override func loadView() {
        /// 根据用户的状态，显示不同的界面
        login ? super.loadView() : setupVisitorView()
    }
    /// 设置访客视图 - 让每一个`小`函数
    private func setupVisitorView() {
        // 替换根视图
        vsview = visitorView()
        
        view = vsview
        // 添加监听方法
        
        // 添加监听方法
        vsview?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        vsview?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        // 设置导航栏按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "visitorViewDidRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "visitorViewDidLogin")
    }
}

// MARK: - 访客视图监听方法
extension visitorViewController {
    
    func visitorViewDidRegister() {
        print("注册")
    }
    
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
}
